/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package network;

import java.net.InetAddress;
import java.net.DatagramSocket;
import java.io.IOException;

/**
 *
 * @author pol
 */
public class UdpClient {

    public UdpClient(InetAddress ia, int port) throws IOException {
        INTERNET_ADDRESS = ia;
        UDP_PORT = port;
        socket = new DatagramSocket();
        msgSender = new MessageSender(this, socket);
        msgReader = new MessageReader(this);
    }

    public void run() {
        Thread t = new Thread(msgReader, "reader");
        t.setDaemon(true);
        t.start();
    }

    public void sendMessage(InetAddress ia, int port, String s) throws IOException {
        INTERNET_ADDRESS = ia;
        UDP_PORT = port;
        msgSender = new MessageSender(this, socket);
        msgReader = new MessageReader(this);
        msgSender.sendPacket(s);
    }
    
    private DatagramSocket socket;
    private MessageSender msgSender;
    private MessageReader msgReader;
    public InetAddress INTERNET_ADDRESS;
    public int UDP_PORT;
}
